import {BasicColumn} from '/src/components/Table';
import {FormSchema} from '/src/components/Table';
import {rules} from '/src/utils/helper/validator';
import {render} from '/src/utils/common/renderUtils';
import {getFileAccessHttpUrl} from '@/utils/common/compUtils';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '说明名称',
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: '品牌名称',
    align: 'center',
    dataIndex: 'brandName',
  },
  {
    title: '品牌LOGO',
    align: 'center',
    dataIndex: 'brandLogo',
    customRender: ({text}) => {
      return render.renderImage({text});
    },
  },
  {
    title: '类型',
    align: 'center',
    dataIndex: 'type',
    customRender: ({text}) => {
      if (text === '0') {
        return '手册';
      } else if (text === '1') {
        return '视频';
      }
      return '未知';
    },
  },
  {
    title: '缩略图路径',
    align: 'center',
    dataIndex: 'thumbPath',
    customRender: ({text}) => {
      return render.renderImage({text});
    },
  },
  {
    title: '单价',
    align: 'center',
    dataIndex: 'unitPrice',
  },
  {
    title: '是否付费',
    align: 'center',
    dataIndex: 'pay',
    customRender: ({text}) => {
      if (text === '0') {
        return '免费';
      } else if (text === '1') {
        return '付费';
      }
      return '未知';
    },
  },

  {
    title: '描述',
    align: 'center',
    dataIndex: 'description',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '品牌',
    field: 'brandId',
    component: 'JSearchSelect',
    componentProps: () => {
      const dictOptions = [];
      for (let item of brandList) {
        dictOptions.push(
          {
            text: item['name'],
            value: item['id']+"",
          }
        )
      }
      return {
        dictOptions
      };
    },
    //colProps: { span: 6 },
  },  {
    label: '类型',
    field: 'type',
    component: 'Select',
    componentProps: () => {
      return {
        options: [
          {label: '手册', value: '0', key: '0'},
          {label: '视频', value: '1', key: '1'},
        ],
      };
    },
    //colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '名称',
    field: 'name',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入使用手册名称',
      },
    ],
  },
  {
    label: '品牌',
    field: 'brandId',
    component: 'JSearchSelect',
    rules: [
      {
        required: true,
        message: '请选择品牌',
      },
    ],
    componentProps: () => {
      const dictOptions = [];
      for (let item of brandList) {
        dictOptions.push(
          {
            text: item['name'],
            value: item['id']+"",
          }
        )
      }
      return {
        dictOptions
      };
    },
  },
  {
    label: '类型',
    field: 'type',
    component: 'Select',
    rules: [
      {
        required: true,
        message: '请选择类型',
      },
    ],
    defaultValue: '0',
    componentProps: () => {
      return {
        options: [
          {label: '手册', value: '0', key: '0'},
          {label: '视频', value: '1', key: '1'},
        ],
      };
    },
  },
  {
    label: '缩略图路径',
    field: 'thumbPath',
    component: 'JImageUpload',
    componentProps: {
      bizPath: 'manualthumb',
    },
    rules: [
      {
        required: true,
        message: '请上传缩略图',
      },
    ],
  },
  {
    label: '手册文件',
    field: 'path',
    component: 'JUpload',
    rules: [
      {
        required: true,
        message: '请上传手册文件',
      },
    ],
    componentProps: {
      bizPath: 'manual',
      maxCount: 1,
    },
  },
  {
    label: '单价（元）',
    field: 'unitPrice',
    component: 'InputNumber',
    defaultValue: 0,
  },
  {
    label: '手册类型',
    field: 'pay',
    component: 'RadioGroup',
    defaultValue: '0',
    componentProps: () => {
      return {
        options: [
          {label: '免费', value: '0', key: '0'},
          {label: '收费', value: '1', key: '1'},
        ],
      };
    },
  },

  {
    label: '描述',
    field: 'description',
    component: 'InputTextArea',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '名称', order: 0, view: 'text', type: 'string'},
  type: {
    title: '类型',
    order: 1,
    view: 'list',
    type: 'string',
    enum: [
      {title: '手册', value: '0'},
      {title: '视频', value: '1'},
    ],
  },
  description: {title: '描述', order: 2, view: 'text', type: 'string'},
  path: {title: '文件路径', order: 3, view: 'text', type: 'string'},
  thumbPath: {title: '缩略图路径', order: 4, view: 'text', type: 'string'},
  unitPrice: {title: '单价', order: 5, view: 'number', type: 'number'},
  pay: {title: '0免费 1收费', order: 6, view: 'text', type: 'string'},
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}


// 品牌数据
export const brandList = []
